package com.ssm.lzh.serachId;

import org.springframework.stereotype.Service;

import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

@Service
public class MemberId {


    public String createMemberId(String value){
        String numberStr = "";
//        System.out.println(value.substring(0,8));
        if(value==null){
            String dateNowStr = new SimpleDateFormat("yyyyMMdd").format(new Date());
            numberStr = new DecimalFormat("000").format(1);
            System.out.println(dateNowStr+"=="+ numberStr);
            return dateNowStr + numberStr;
        }
        String dateNowStr = new SimpleDateFormat("yyyyMMdd").format(new Date());
        System.out.println(dateNowStr);
        //判断是今天吗
        if (!value.substring(0, 8).equals(dateNowStr)) {
            //从1开始
            numberStr = new DecimalFormat("000").format(1);
            return dateNowStr + numberStr;
        }

        numberStr = new DecimalFormat("000").format(Integer.parseInt(value.substring(value.length() - 3, value.length())) + 1);
        value = dateNowStr + numberStr;
        return value;
    }

}
